<template>
  <base-content>
    <BCRUD
      entity="Task"
      :form="form"
      :columns="columns"
      :isGrid="false"
    ></BCRUD>
  </base-content>
</template>

<script>
import { toArrayEnum } from "src/utils/enum";
import BCRUD from "components/BCRUD.vue";

export default {
  components: { BCRUD },
  data() {
    return {
      form: {
        // avatar: {
        //   is: "form-image",
        //   size: "100px",
        //   changeable: true
        // },
        id: {
          is: "q-input",
          label: "ID",
          readonly: true,
          whenShow: "upt"
        },
        title: {
          is: "q-input",
          type: "text"
        },
        subject: {
          is: "q-input",
          type: "text"
        },
        content: {
          is: "q-input",
          type: "textarea",
          label: "内容"
        },
        remark: {
          is: "q-input",
          type: "textarea"
        },
        group: {
          is: "q-input",
          type: "text"
        },
        creator: {
          is: "q-input",
          type: "text"
        },
        type: {
          is: "q-select",
          emitValue: true,
          mapOptions: true,
          default: 0,
          options: toArrayEnum(["通知", "填表", "打卡"])
        },
        status: {
          label: "状态",
          is: "q-select",
          emitValue: true,
          mapOptions: true,
          default: 0,
          options: [
            {
              label: "正常",
              value: 0
            },
            {
              label: "禁用",
              value: 1
            }
          ]
        },
        createdAt: {
          is: "q-input",
          type: "text",
          readonly: true
        },
        updatedAt: {
          is: "q-input",
          type: "text",
          readonly: true
        },
        deletedAt: {
          is: "q-input",
          type: "text",
          label: "删除时间",
          readonly: true
        }
        // roles: {
        //   is: "form-roles"
        // },
        // setting: {
        //   is: "form-setting"
        // }
      },
      columns: [
        {
          name: "id",
          required: true,
          label: "ID",
          field: row => row.id,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@="
        },
        {
          name: "title",
          required: true,
          label: "名称",
          field: row => row.title,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@like"
        },
        {
          name: "subject",
          required: true,
          label: "主题",
          field: row => row.subject,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@="
        },
        {
          name: "remark",
          required: true,
          label: "备注",
          field: row => row.remark,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@in"
        },
        {
          name: "group",
          required: true,
          label: "所属组",
          field: row => row.group,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@=",
          is: "cell-link",
          bindProps() {
            return {
              href: id => `/group?where=id:${id}`
            };
          }
        },
        {
          name: "creator",
          required: true,
          label: "创建者",
          field: row => row.creator,
          format: val => `${val}`,
          sortable: true,
          searchModify: "@=",
          is: "cell-link",
          bindProps() {
            return {
              href: id => `/user/account?where=id:${id}`
            };
          }
        },
        {
          name: "type",
          required: true,
          label: "类型",
          field: row => row.type,
          format: val => `${["通知", "填表", "打卡"][val]}`,
          sortable: true
        },
        {
          name: "status",
          required: true,
          label: "状态",
          field: row => row.status,
          format: val => `${["正常", "禁用"][val]}`,
          sortable: true
        },
        {
          name: "createdAt",
          required: true,
          label: "创建时间",
          field: row => row.createdAt,
          format: val => `${val}`
        },
        {
          name: "updatedAt",
          required: true,
          label: "更新时间",
          field: row => row.updatedAt,
          format: val => `${val}`
        }
      ]
    };
  }
};
</script>

<style></style>
